<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-upload
        class="avatar-uploader"
        action="#"
        list-type="picture-card"
        :http-request="uploadFn"
      >
        <img v-if="imageUrl" :src="imageUrl" class="avatar">
        <i v-else class="el-icon-plus avatar-uploader-icon" />
      </el-upload>
    </div>
  </div>
</template>

<script>
import COS from 'cos-js-sdk-v5'
// SECRETID 和 SECRETKEY请登录 https://console.cloud.tencent.com/cam/capi 进行查看和管理
const cos = new COS({
  SecretId: 'AKID4wYv4xaw2sSmpdBSTEjxvfAPN5XjeJiq',
  SecretKey: 'tWt0rREl22mGTQ6bqoVw72g4E8l8F5fy'
})
export default {
  methods: {
    uploadFn(data) {
      console.log('上传', data)
      cos.putObject({
        Bucket: 'hr-1314002095', /* 必须 */
        Region: 'ap-guangzhou', /* 存储桶所在地域，必须字段 */
        Key: Date.now().toString(), /* 必须 */
        StorageClass: 'STANDARD',
        Body: data.file, // 上传文件对象
        onProgress: function(progressData) {
          console.log(JSON.stringify(progressData))
        }
      }, function(err, data) {
        console.log(err || data)
      })
    }
  }
}
</script>

  <style>

  </style>
